﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
namespace EETOP.OAuthSDK
{
    public sealed class OpenAuthRelyingParty
    {

        public HttpGet Httpget
        {
            get;
            private set;
        }
        public OAuthSettings OAuth_Settings
        {
            get;
            set;
        }
        public AuthenticationResponse Response
        {
            get;
            set;
        }

        
        public HttpGet CreateRequest()
        {
            return CreateRequest(this.OAuth_Settings);
        }
        public HttpGet CreateRequest(OAuthSettings settings)
        {
            var httpRequest = HttpRequestFactory.CreateHttpRequest(Method.GET, settings) as HttpGet;
            httpRequest.GetRequestToken();
            Httpget = httpRequest;
            HttpContext.Current.Session["oauth_request_token"] = httpRequest.Token;
            HttpContext.Current.Session["oauth_request_token_secret"] = httpRequest.TokenSecret;
            return httpRequest;
        }
        
       

        public OpenAuthRelyingParty(OAuthSettings oauth_Settings)
        {
            this.OAuth_Settings = oauth_Settings;
            if (!string.IsNullOrEmpty(HttpContext.Current.Request["oauth_verifier"]))
            {
                var httpget = HttpRequestFactory.CreateHttpRequest(Method.GET, oauth_Settings) as HttpGet;
                httpget.Token = HttpContext.Current.Session["oauth_request_token"].ToString();
                httpget.TokenSecret = HttpContext.Current.Session["oauth_request_token_secret"].ToString();
                httpget.Verifier = HttpContext.Current.Request["oauth_verifier"];
                httpget.GetAccessToken();
                Response = new AuthenticationResponse();
                Response.Oauth_Access_Token = httpget.Token;
                Response.Oauth_Access_Token_Secret = httpget.TokenSecret;
            }
        }

      
    }

   
}
